#include "renrendai.h"
#include "renrendaigetlist.h"
#include "renrendailogin.h"
#include "renrendaigetdetail.h"
#include "ilog.h"

struct TaskEnv* gTenv = NULL;
//struct TaskEnv gTenv = NULL;

extern struct WorkerInitStruct login;
extern struct WorkerInitStruct debitlist;
extern struct WorkerInitStruct debitdetail;
struct WorkerInitStruct* WInitStructArray[] = {
	&login,		/* 登入界面 */
	&debitlist,	/* list界面 */
	&debitdetail,	/* list界面 */
	NULL
};

static int RenrendaiTaskInit(struct TaskEnv *tenv);
static int RenrendaiTaskExit(struct TaskEnv *tenv);

/* task的初始化结构体 */
struct TaskInitStruct InitStruct 
= 	{ 	"renrendai", 
		"./",
		"tasklog",
		"renrendai.so", 
		60, 
		RenrendaiTaskInit,
		NULL,
		WInitStructArray
	};

static int RenrendaiTaskInit(struct TaskEnv *tenv)
{
	ErrorLog( __FILE__ , __LINE__ , "task[%s] TaskInit" , tenv->taskname );
	return 0;	
}

int CheckResp(struct HttpReq *req)
{
	if (req->result == 0 && req->rerrno == 0) 
		return RSP_OK;

	if (req->rerrno =  TOOFASTCODE)
		return RSP_TOOFAST;

	return 	RSP_UNKNOW;
}

/* 整个进程的入口, */
int SoMain(struct TaskEnv *tenv)
{
	int r = 0;
	/* 设置logfile */
	gTenv = tenv;	
	SetTaskLog(&InitStruct);

	ErrorLog( __FILE__ , __LINE__ , "task[%s] do SoMain", tenv->taskname );
	r = DoTaskManager(gTenv, &InitStruct);
	ErrorLog( __FILE__ , __LINE__ , "task[%s] end SoMain, r[%d]" , tenv->taskname, r );

	return r;
}


int main()
{
	struct TaskEnv env;
	memset(&env, 0x00, sizeof(struct TaskEnv));
	SoMain(&env);
	return 0;
}

